# -*- coding: utf-8 -*-
import scrapy
from ..items import DoutuItem


class DoutuSpiderSpider(scrapy.Spider):
    name = 'doutu_spider'
    # allowed_domains = ['xxx']
    start_urls = ['http://www.doutula.com/photo/list/']
    for i in range(2, 11):
        url = 'http://www.doutula.com/photo/list/?page=' + str(i)
        start_urls.append(url)

    def parse(self, response):
        all_img = response.xpath("//a[@class='col-xs-6 col-sm-3']/img[@class='img-responsive lazy image_dta']")
        for img in all_img:
            alt = img.xpath("./@alt")[0].extract()
            src = img.xpath("./@data-original")[0].extract()[:-4]
            print(alt, src)
            item = DoutuItem()
            item['alt'] = alt
            item['src'] = src
            yield item
